package com.fotoloka.view;

import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JLabel;

@SuppressWarnings("serial")
public class Rotulo extends JLabel {

	private boolean centralizado = true;

	private JComponent parent;

	public Rotulo(JComponent parent, String texto) {
		this.setText(texto);
		this.parent = parent;
	}

	public Rotulo(JComponent parent, String texto, boolean centralizado) {
		this(parent, texto);
		this.centralizado = centralizado;
	}

	@Override
	protected void paintComponent(Graphics g) {

		
		
		if (centralizado) {

			int width = this.getWidth();
			int height = this.getHeight(); 	

			int x = (parent.getWidth() - width) / 2;
			int y = (parent.getHeight() - height) / 2;
			
			if(x != getX() || y != getY()) {
				this.setBounds(x, y, width, height);
			}
		}
		
		super.paintComponent(g);
		
	}

}
